package cn.wolfcode.car.business.service.impl;

import cn.wolfcode.car.business.domain.CustomerLinkmen;
import cn.wolfcode.car.business.mapper.LinkmenMapper;
import cn.wolfcode.car.business.query.LinkmenQuery;
import cn.wolfcode.car.business.service.ILinkmenService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.util.Convert;
import cn.wolfcode.car.shiro.ShiroUtils;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class LinkmenServiceImpl implements ILinkmenService {

    @Autowired
    private LinkmenMapper linkmenMapper;



    @Override
    public TablePageInfo<CustomerLinkmen> query(LinkmenQuery qo) {
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        return new TablePageInfo<CustomerLinkmen>(linkmenMapper.selectForList(qo));
    }


    @Override
    public void save(CustomerLinkmen linkmen) {
        linkmen.setInputTime(new Date());
        linkmen.setInputUser(ShiroUtils.getUserId());
        // 新增操作
        linkmenMapper.insert(linkmen);
    }

    @Override
    public CustomerLinkmen get(Long id) {
        return linkmenMapper.selectByPrimaryKey(id);
    }



    @Override
    public List<CustomerLinkmen> list() {
        return linkmenMapper.selectAll();
    }

    @Override
    public void update(CustomerLinkmen customerLinkmen) {
        customerLinkmen.setInputUser(ShiroUtils.getUserId());
        linkmenMapper.updateByPrimaryKey(customerLinkmen);
    }

    @Override
    public List<CustomerLinkmen> selectByCustomerId(Long id) {
        return linkmenMapper.selectByCustomerId(id);
    }

    @Override
    public void deleteBatch(String ids) {
        Long[] dictIds = Convert.toLongArray(ids);
        for (Long dictId : dictIds) {
            linkmenMapper.deleteByPrimaryKey(dictId);
        }
    }


}
